package com.zhuoyue.elmt.web;

import com.eit.eitsite.common.mapper.JsonMapper;
import com.eit.eitsite.common.web.BaseController;
import com.zhuoyue.elmt.data.ResultData;
import com.zhuoyue.elmt.entity.AdministrativeAreas;
import com.zhuoyue.elmt.entity.XtSbzl;
import com.zhuoyue.elmt.service.AdministrativeAreasService;
import com.zhuoyue.elmt.service.XtSbzlService;
import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by admin on 2016/12/17.
 */
@Controller
@RequestMapping(value = "${adminPath}/elmt/areas")
public class AdministrativeAreasController extends BaseController {
    @Autowired
    private AdministrativeAreasService service;

    @Autowired
    private XtSbzlService xtSbzlService;

    @RequestMapping(value = {"findAll"})
    public String findAll(AdministrativeAreas deviceParameters, HttpServletRequest request, HttpServletResponse response, Model model) {
        List<AdministrativeAreas> areasList = service.getAll();
        model.addAttribute("areaslist", areasList);
        return "zhuoyue/elmt/selectAreas";
    }

    @RequestMapping(value = {"findDeviceTypeAll"})
    public String findDeviceTypeAll(XtSbzl xtSbzl, HttpServletRequest request, HttpServletResponse response, Model model) {
        List<XtSbzl> sbzlList = xtSbzlService.findDeviceTypeAll();
        model.addAttribute("sbzlList", sbzlList);
        return "zhuoyue/elmt/deviceTypeList";
    }

    @RequestMapping(value = "/listXzqy")
    public String listXzqy(HttpServletResponse response) {
        ResultData<List<AdministrativeAreas>> resultData = new ResultData();
        try {
            List<AdministrativeAreas> areasList = service.getAll();
            resultData.setCode("SUCC");
            resultData.setMessage("SUCCESS");
            resultData.setList(areasList);
        } catch (Exception e) {
            resultData.setCode("FAIL");
            resultData.setMessage("行政区域查询出现异常！");
            e.printStackTrace();
        }
        return super.renderString(response, resultData);
    }

    @RequestMapping(value = "/listSbzl")
    public String listSbzl(HttpServletResponse response) {
        ResultData<List<XtSbzl>> resultData = new ResultData();
        try {
            List<XtSbzl> sbzlList = xtSbzlService.findDeviceTypeAll();
            resultData.setCode("SUCC");
            resultData.setMessage("SUCCESS");
            resultData.setList(sbzlList);
        } catch (Exception e) {
            resultData.setCode("FAIL");
            resultData.setMessage("设备种类查询出现异常！");
            e.printStackTrace();
        }
        return super.renderString(response, resultData);
    }
}
